﻿@model Xms.Web.Customize.Models.WorkFlowInstanceModel

<div class="panel panel-default">
    <div class="panel-heading">
        <h3 class="panel-title">
            <a data-toggle="collapse"
               href="#collapseTwo">
                <strong>@app.PrivilegeTree?.LastOrDefault().DisplayName - @Model.FlowInfo.Name</strong>
            </a>
        </h3>
    </div>
    <div id="collapseTwo" class="panel-collapse collapse in">
        <div class="panel-body">
            <div class="mb-2 toolbar">

                <div class="">
                    <form id="searchForm" class="hide">
                        <input type="hidden" name="workflowid" value="@Model.WorkFlowId" />
                    </form>
                    <div class="" id="gridview">
                        <div class="datagrid-view"></div>
                    </div>
                </div>
            </div>
        </div>
    </div>
</div>
@section Header {
    <link href="~/content/customize/css/common.css?v=@app.PlatformSettings.VersionNumber" rel="stylesheet">
    <link href="~/content/js/jquery-ui-1.10.3/themes/base/jquery.ui.all.css?v=@app.PlatformSettings.VersionNumber" rel="stylesheet">
    <link href="~/content/js/grid/pqgrid.dev.css?v=@app.PlatformSettings.VersionNumber" rel="stylesheet">
    <link id="themeLink" href="~/content/css/theme/@(app.Theme).css" rel="stylesheet" />
}
@section Scripts {
    <script src="/content/js/jquery-ui-1.10.3/ui/jquery.ui.button.js?v=@app.PlatformSettings.VersionNumber"></script>
    <script src="/content/js/jquery-ui-1.10.3/ui/jquery.ui.mouse.js?v=@app.PlatformSettings.VersionNumber"></script>
    <script src="/content/js/jquery-ui-1.10.3/ui/jquery.ui.autocomplete.js?v=@app.PlatformSettings.VersionNumber"></script>
    <script src="/content/js/jquery-ui-1.10.3/ui/jquery.ui.draggable.js?v=@app.PlatformSettings.VersionNumber"></script>
    <script src="/content/js/jquery-ui-1.10.3/ui/jquery.ui.resizable.js?v=@app.PlatformSettings.VersionNumber"></script>
    <script src="/content/js/jquery-ui-1.10.3/ui/jquery.ui.tooltip.js?v=@app.PlatformSettings.VersionNumber"></script>
    <script src="~/content/js/fetch.js?v=@app.PlatformSettings.VersionNumber"></script>
    <script src="~/content/js/common/filters.js?v=@app.PlatformSettings.VersionNumber"></script>
    <script src="/content/js/grid/pqgrid.dev.js?v=@app.PlatformSettings.VersionNumber"></script>
    <script src="/content/js/grid/localize/pq-localize-zh.js?v=@app.PlatformSettings.VersionNumber"></script>
    <script src="/content/js/cdatagrid.js?v=@app.PlatformSettings.VersionNumber"></script>
    <script src="/content/js/jquery.bootpag.min.js?v=@app.PlatformSettings.VersionNumber"></script>
    <script src="/content/js/jquery.form.js?v=@app.PlatformSettings.VersionNumber"></script>
    <script src="/content/js/jquery.bootpag.min.js?v=@app.PlatformSettings.VersionNumber"></script>
    <script src="/content/js/jquery.form.js?v=@app.PlatformSettings.VersionNumber"></script>
    <script>
        var pageUrl = '';
        var solutionid = '';
        var statelist = ['<span class="label label-default">等待中</span>','<span class="label label-info">处理中</span>','<p class="label label-success"><span class="glyphicon glyphicon-ok"></span> 通过</p>','<p class="label label-danger"><span class="glyphicon glyphicon-remove"></span> 不通过</p>',' <span class="label label-default">作废</span>','<span class="label label-default">已撤消</span>','','','','']
        $(function () {
            var theaders = {
                'name': '提交者',
                'statecode': '状态',
                'descript': '说明',
                'createdon': '创建时间',
                'enddon': '结束时间',
                'operation':'@app.T["operation"]'
            }
            //列数据配置数据
            var columnConfigs = [
            //从新配置复选框列的渲染方式，
                {
                    title: "", dataIndx: "recordid", maxWidth: 48, minWidth: 48, align: "center", resizable: false,
                    type: 'checkBoxSelection', cls: 'ui-state-default', sortable: false, editable: false,
                    render: function (ui) {
                      //  console.log(ui)
                        return '<input type="checkbox" value="' + ui.rowData.workflowinstanceid + '" name="recordid" class="">'
                    },
                    cb: { all: true, header: true }
                },
                {
                    title: "", dataIndx: "name", maxWidth: 30, minWidth: 30, align: "center", resizable: false,
                     cls: 'ui-state-default', sortable: false, editable: false,
                    hidden:true,
                    render: function (ui) {
                        //  console.log(ui)
                        return '<input type="hidden" value="' + ui.rowData.workflowinstanceid + '" name="componenttypename" class="">'
                    },
                    cb: { all: true, header: true }
                },
                { "dataIndx": "applicantname", "title": theaders.name, editable: false, "dataType": "string", "width": 150, "isprimaryfield": false, "attributetypename": "string" },
                { "dataIndx": "statecode", "title": theaders.statecode, editable: false, "dataType": "string", "width": 100, "isprimaryfield": false, "attributetypename": "string", render: function (ui, a, b) {
                        var datas = ui.rowData;
                        var dataIndx = ui.dataIndx;
                        var column = ui.column;
                        var recordid = datas[dataIndx];

                    if (recordid == true) {
                        return statelist[recordid]
                        } else {
                            return statelist[recordid]
                        }
                    } },
                { "dataIndx": "description", "title": theaders.descript, "dataType": "string", editable: false, "width": 150, "isprimaryfield": false, "attributetypename": "string" },

                { "dataIndx": "createdon", "title": theaders.createdon, editable: false, "dataType": "string", "width": 150, "isprimaryfield": false, "attributetypename": "string" },
                 { "dataIndx": "completedon", "title": theaders.enddon, editable: false, "dataType": "string", "width": 150, "isprimaryfield": false, "attributetypename": "string" },
                {
                    title: "操作", editable: false, minWidth: 220,width:220, notHeaderFilter: true, editable: false, sortable: false, render: function (ui) {
                        var datas = ui.rowData;
                        var dataIndx = ui.dataIndx;
                        var column = ui.column;
                        var recordid = datas[dataIndx];
                        var html = ''
                        html = '<a class="btn btn-info btn-xs" href="@("/"+app.OrganizationUniqueName)/customize/flow/WorkFlowProcess?workflowinstanceid=' + datas.workflowinstanceid + '" ><span class="glyphicon glyphicon-edit glyphicon-link"></span> 详情</a>'
                            + ' <a class="btn btn-warning btn-xs ' + (datas.statecode == 1 ? '' : 'hide') + '" href="javascript:Cancel(\'' + datas.workflowinstanceid + '\')"><span class="glyphicon glyphicon-refresh"></span> 撤消</a>'
                            + '<a class="btn btn-info btn-xs hide"><span class="glyphicon glyphicon-share-alt"></span> 指派</a>';
                        return html
                    }
                }
            ];
           var url = ORG_SERVERURL + '/customize/@app.ControllerName/@app.ActionName?LoadData=true&';
            var $form = $('#searchForm');
            var roles_filters = new XmsFilter();
            var datagridconfig = {
                scrollModel: { autoFit: true },
                baseUrl: url,
                columnConfigs: columnConfigs,//字段配置信息
                context: $('#gridview'),//底部操作按钮方法触发
                filters: roles_filters,//post提交时过滤条件
                searchForm: $form//GET提交时查询的数据
            };
            $('.datagrid-view').xmsDataTable(datagridconfig);
        });
        function rebind() {
             $('.datagrid-view').cDatagrid('refreshDataAndView')
        }
        function Cancel(id) {
            Xms.Web.Confirm('撤消', '确定要撤消吗？', function () {
                Xms.Ajax.Post(ORG_SERVERURL + '/api/workflow/cancel/' + id, null, function (response) {
                    if (response.IsSuccess) {
                        rebind();
                    }
                    else {
                        Xms.Web.Toast(response.Content, response.IsSuccess);
                    }
                });
            });
        }
    </script>
}